using System.Collections;
using System.Windows.Forms;

namespace PodInvaders
{
	public class ListViewItemSorter : IComparer
	{
		private int[] _columns;

		public ListViewItemSorter(int[] Columns)
		{
			_columns = Columns;
		}

		public int Compare(object x, object y)
		{
			int result = 0;
			int column = 0;

			string t1, t2;
			int n1, n2;

			while(result == 0 && column < _columns.Length)
			{
				t1 = ((ListViewItem) x).SubItems[_columns[column]].Text;
				t2 = ((ListViewItem) y).SubItems[_columns[column]].Text;

				if(int.TryParse(t1, out n1) && int.TryParse(t2, out n2))
					result = n1.CompareTo(n2);
				else
					result = string.Compare(t1, t2);

				column++;
			}

			return result;
		}
	}
}